using Domain.Entities;
using Domain.Entities.Enums;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using System;
using System.Web;
using System.Configuration;

namespace UserInterface.Misc
{
    class UITools
    {
        private static Dictionary<TopicType, string> topicTypeImageUrls = new Dictionary<TopicType,string>();

        static UITools()
        {
            topicTypeImageUrls[TopicType.Announcement] = "Templates/Default/Images/topic-type-announcement.gif";
            topicTypeImageUrls[TopicType.Sticky] = "Templates/Default/Images/topic-type-sticky.gif";
            topicTypeImageUrls[TopicType.Normal] = "Templates/Default/Images/topic-type-normal.gif";
            topicTypeImageUrls[TopicType.Faq] = "Templates/Default/Images/topic-type-faq.gif";
        }

        public static int GuestUserId
        {
            get { return Convert.ToInt32(ConfigurationManager.AppSettings["GuestUserId"]); }
        }

        public static string GetTopicTypeImageUrl(Topic topic)
        {
            return topicTypeImageUrls[topic.Type];
        }

        public static void AddConfirmMessage(WebControl control, string confirmMessage)
        {
            control.Attributes.Add("onclick", "return confirm('" + confirmMessage + "');");
        }

        public static string getAttachmentDownloadURL(Attachment attachment)
        {
            if ( attachment.Id == 0 )
            {
                return String.Format(
                    "DownloadTempAttachment.aspx?data={0}&name={1}&type={2}",
                    HttpUtility.UrlEncode(EncryptTools.Encrypt(attachment.FilePath)),
                    HttpUtility.UrlEncode(attachment.FileName),
                    HttpUtility.UrlEncode(attachment.FileType)
                );
            }
            return "DownloadAttachment.aspx?id=" + attachment.Id;
        }
    }
}